<?

/**
* Fetch the amount of
* Account Payable(A/P) outstanding
*
*/
if($isApprove){

  /**
  * Insert into A/P DB
  * and set status to _OUTSTANDING,
  * reference would take purchasing's
  *
  */
  $CFetchers->fetchLastMutationNo($COracle,
                                  $lstSubDetail["REFERENCE"][0],
                                  $SourceDb->fetchValue("srcDbMutIvcSupplier"),
                                  $lastMutNumber);

  /**
   * since this is an payment out
   * then the amount should be (-)
   */
  $amount = $lstSubDetail["AMOUNT"][0] * -1;

  $values = "  ".$periode.",    ".
            " '".$lstHeader["SUPPLIER_CODE"][0]."', ".
            " '".$lstHeader["NOTA_SRC"][0]."',      ".
            " ' ',   ".
            "  ".$txDate.",   ".
            "  ".$txDate.",   ".
            "  ".$dueDate.",  ".
            "  ".$txType.",   ".
            "  ".$lstHeader["PAYABLE"][0]." ,  ".
            "  ".$lastMutNumber."  ";

  $CHandlers->insToMutInvoice($COracle,
                              "SUPPLIER_CODE",
                              $values,
                              $SourceDb->fetchValue("srcDbMutIvcSupplier"));
}else{

  /**
   * check if this AP is still clean
   */
  $CLFetchers->fetchOutstandingRemain($COracle,
                                      $lstHeader["SUPPLIER_CODE"][0],
                                      $periode,
                                      $lstHeader["NOTA_SRC"][0],
                                      $SourceDb->fetchValue("srcDbMutIvcSupplier"),
                                      $nRemain,
                                      $resRemain);

  if($nRemain > 1){

    $Misc->usrDieJs("Error: this TX is no longer clean therefore can't be canceled");
  }else{

    /**
     * process the cancelation
     */
    $CHandlers->dbEntDelete2($COracle,
                             $refId,
                             $SourceDb->fetchValue("srcDbMutIvcSupplier"));
  }
}

?>